package com.huizu.goods.service.impl;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huizu.goods.mapper.ShopCouponMapper;
import com.huizu.goods.mapper.ShopNewsMapper;
import com.huizu.goods.domain.ShopCoupon;
import com.huizu.goods.domain.ShopNews;
import com.huizu.goods.service.IShopCouponService;
import com.huizu.common.core.text.Convert;

/**
 * 优惠卷管理Service业务层处理
 * 
 * @author huizu
 * @date 2022-02-10
 */
@Service
public class ShopCouponServiceImpl implements IShopCouponService {
	@Autowired
	private ShopCouponMapper shopCouponMapper;
	@Autowired
	private ShopNewsMapper shopNewsMapper;

	/**
	 * 查询优惠卷管理
	 * 
	 * @param id
	 *            优惠卷管理主键
	 * @return 优惠卷管理
	 */
	@Override
	public ShopCoupon selectShopCouponById(Long id) {
		return shopCouponMapper.selectShopCouponById(id);
	}

	/**
	 * 查询优惠卷管理列表
	 * 
	 * @param shopCoupon
	 *            优惠卷管理
	 * @return 优惠卷管理
	 */
	@Override
	public List<ShopCoupon> selectShopCouponList(ShopCoupon shopCoupon) {
		return shopCouponMapper.selectShopCouponList(shopCoupon);
	}

	/**
	 * 新增优惠卷管理
	 * 
	 * @param shopCoupon
	 *            优惠卷管理
	 * @return 结果
	 */
	@Override
	public int insertShopCoupon(ShopCoupon shopCoupon) {
		if (shopCoupon.getShopId().longValue() == 1) {
			shopCoupon.setName("平台优惠卷");
		} else {
			ShopNews  news=shopNewsMapper.selectShopNewsById(shopCoupon.getShopId());
			shopCoupon.setName(news.getName());
		}
		shopCoupon.setCreateDate(new Date());
		return shopCouponMapper.insertShopCoupon(shopCoupon);
	}

	/**
	 * 修改优惠卷管理
	 * 
	 * @param shopCoupon
	 *            优惠卷管理
	 * @return 结果
	 */
	@Override
	public int updateShopCoupon(ShopCoupon shopCoupon) {
		return shopCouponMapper.updateShopCoupon(shopCoupon);
	}

	/**
	 * 批量删除优惠卷管理
	 * 
	 * @param ids
	 *            需要删除的优惠卷管理主键
	 * @return 结果
	 */
	@Override
	public int deleteShopCouponByIds(String ids) {
		return shopCouponMapper.deleteShopCouponByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除优惠卷管理信息
	 * 
	 * @param id
	 *            优惠卷管理主键
	 * @return 结果
	 */
	@Override
	public int deleteShopCouponById(Long id) {
		return shopCouponMapper.deleteShopCouponById(id);
	}
}
